package com.diaohw.module.metadata.controller.meta;

import com.diaohw.module.metadata.obj.dto.MetaDTO;
import com.diaohw.module.metadata.obj.dto.MetaItemDTO;
import com.diaohw.module.metadata.obj.query.MetaItemQuery;
import com.diaohw.module.metadata.obj.query.MetaQuery;
import com.diaohw.module.metadata.obj.vo.MetaItemVO;
import com.diaohw.module.metadata.obj.vo.MetaVO;
import com.diaohw.module.metadata.service.MetaService;
import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.common.validator.InsertGroup;
import com.diaohw.platform.common.validator.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 元数据信息 前端控制器
 * </p>
 *
 * @author D-Hw
 * @since 2025-04-07
 */
@Tag(name = "元数据信息")
@RestController
@RequestMapping("/meta")
public class MetaController {

    @Resource
    private MetaService service;

    @PostMapping
    @Operation(summary = "新增")
    public Boolean create(@RequestBody @Validated(InsertGroup.class) MetaDTO data) {
        return service.create(data);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新")
    public Boolean update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) MetaDTO data) {
        return service.update(id, data);
    }

    @PostMapping("/item")
    @Operation(summary = "数据项新增")
    public Boolean create(@RequestBody @Validated(InsertGroup.class) MetaItemDTO data) {
        return service.create(data);
    }

    @PutMapping("/item/{id}")
    @Operation(summary = "数据项更新")
    public Boolean update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) MetaItemDTO data) {
        return service.update(id, data);
    }


    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @DeleteMapping("/item/{id}")
    @Operation(summary = "删除")
    public Boolean deleteItem(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "依据ID查看信息")
    public MetaVO detail(@PathVariable("id") String id) {
        return service.detail(id);
    }


    @GetMapping
    @Operation(summary = "查询列表")
    public List<MetaVO> all(MetaQuery query) {
        return service.findByList(query);
    }

    @GetMapping("/item")
    @Operation(summary = "数据项查询列表")
    public List<MetaItemVO> allItem(MetaItemQuery query) {
        return service.findByList(query);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<MetaVO> page(MetaQuery query) {
        return service.findByPage(query);
    }


    @GetMapping("/item/page")
    @Operation(summary = "数据项分页查看")
    public PageResultVo<MetaItemVO> pageItem(MetaItemQuery query) {
        return service.findByPage(query);
    }

}
